package com.demoo.zjsu.service.smartwebsite.zjgsu;

import com.demoo.zjsu.model.smartwebsite.PageOne;
import com.demoo.zjsu.service.smartwebsite.BaseFactory;
import com.demoo.zjsu.service.smartwebsite.Page;
import com.demoo.zjsu.string.smartwebsite.WebsiteStrings;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by jshjsh on 2016/8/16.
 *
 */
@Service
public class BasePackageFactory extends BaseFactory{

    @Override
    public PageOne getPageOne(Elements e) {
        PageOne pageOne = new PageOne();
        pageOne.setContent(e.toString());
        return pageOne;
    }

    @Override
    public Elements getMain(Document document) {
        return document.select("[cellpadding=2]");
    }

    @Override
    public void filterElse(Elements elements) {
        String src = elements.select("a[href$=.pdf]").attr("href");
        src = src.replace("http://www.hzic.edu.cn/", "");
        elements.attr("href", src);
    }



    @Override
    public Page getPage() {
        Page page = new Page();
        page.setCategories(WebsiteStrings.categories);
        page.setLinkUrls(WebsiteStrings.urls);
        return page;
    }

}
